home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import symjava.lang.Bignum;
- import symjava.sql.Date;
- import symjava.sql.SQLException;
- import symjava.sql.Time;
- import symjava.sql.Timestamp;
-
- abstract class CharField extends Field {
- String _data;
-
- void read(DataInputStream in) throws SQLException, IOException, ErrorException {
- super.read(in);
- this._data = new String("");
- }
-
- void write(DataOutputStream out) throws IOException {
- super.write(out);
- }
-
- public String getString() throws SQLException {
- return ((Field)this).isNull() ? null : new String(this._data);
- }
-
- public boolean getBoolean() throws SQLException {
- if (((Field)this).isNull()) {
- return false;
- } else {
- byte b = (byte)this._data.charAt(0);
- return b != 0;
- }
- }
-
- public byte getByte() throws SQLException {
- if (((Field)this).isNull()) {
- return 0;
- } else {
- try {
- Double d = new Double(this._data);
- return (byte)d.intValue();
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public short getShort() throws SQLException {
- if (((Field)this).isNull()) {
- return 0;
- } else {
- try {
- Double d = new Double(this._data);
- return (short)d.intValue();
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public int getInt() throws SQLException {
- if (((Field)this).isNull()) {
- return 0;
- } else {
- try {
- Double d = new Double(this._data);
- return d.intValue();
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public long getLong() throws SQLException {
- if (((Field)this).isNull()) {
- return 0L;
- } else {
- try {
- Double d = new Double(this._data);
- return d.longValue();
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public float getFloat() throws SQLException {
- if (((Field)this).isNull()) {
- return 0.0F;
- } else {
- try {
- Double d = new Double(this._data);
- return d.floatValue();
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public double getDouble() throws SQLException {
- if (((Field)this).isNull()) {
- return (double)0.0F;
- } else {
- try {
- Double d = new Double(this._data);
- return d;
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public Bignum getBignum(int scale) throws SQLException {
- return ((Field)this).isNull() ? null : new Bignum(this._data, scale);
- }
-
- public byte[] getBytes() throws SQLException {
- if (((Field)this).isNull()) {
- return new byte[0];
- } else {
- try {
- byte[] dst = new byte[this._data.length()];
- this._data.getBytes(0, this._data.length(), dst, 0);
- return dst;
- } catch (Exception e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
- }
-
- public Date getDate() throws SQLException {
- return ((Field)this).isNull() ? null : Date.valueOf(this._data);
- }
-
- public Time getTime() throws SQLException {
- return ((Field)this).isNull() ? null : Time.valueOf(this._data);
- }
-
- public Timestamp getTimestamp() throws SQLException {
- return ((Field)this).isNull() ? null : Timestamp.valueOf(this._data);
- }
-
- public InputStream getAsciiStream() throws SQLException {
- return ((Field)this).isNull() ? null : new BinaryInputStream(this._data);
- }
-
- public InputStream getUnicodeStream() throws SQLException {
- return ((Field)this).isNull() ? null : new BinaryInputStream(this._data);
- }
-
- public InputStream getBinaryStream() throws SQLException {
- return ((Field)this).isNull() ? null : new BinaryInputStream(this._data);
- }
-
- public void setBoolean(boolean x) throws SQLException {
- if (x) {
- this._data = new String("true");
- } else {
- this._data = new String("false");
- }
-
- super._null = false;
- }
-
- public void setByte(byte x) throws SQLException {
- this._data = Integer.toString(x);
- super._null = false;
- }
-
- public void setShort(short x) throws SQLException {
- this._data = Integer.toString(x);
- super._null = false;
- }
-
- public void setInt(int x) throws SQLException {
- this._data = Integer.toString(x);
- super._null = false;
- }
-
- public void setLong(long x) throws SQLException {
- this._data = Long.toString(x);
- super._null = false;
- }
-
- public void setFloat(float x) throws SQLException {
- this._data = Float.toString(x);
- super._null = false;
- }
-
- public void setDouble(double x) throws SQLException {
- this._data = Double.toString(x);
- super._null = false;
- }
-
- public void setBignum(Bignum x) throws SQLException {
- this._data = x.toString();
- super._null = false;
- }
-
- public void setString(String x) throws SQLException {
- this._data = x;
- super._null = false;
- }
-
- public void setBytes(byte[] x) throws SQLException {
- this._data = new String(x, 0);
- super._null = false;
- }
-
- public void setDate(Date x) throws SQLException {
- this._data = x.toString();
- super._null = false;
- }
-
- public void setTime(Time x) throws SQLException {
- this._data = x.toString();
- super._null = false;
- }
-
- public void setTimestamp(Timestamp x) throws SQLException {
- this._data = x.toString();
- super._null = false;
- }
-
- public void setStream(InputStream x, int length) throws SQLException {
- if (length >= 0 && length <= 255) {
- byte[] b = new byte[length];
-
- try {
- x.read(b, 0, length);
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
-
- this._data = new String(b, 0, 0, b.length);
- super._null = false;
- } else {
- throw new SQLException("Stream length out of range.");
- }
- }
-
- public void setAsciiStream(InputStream x, int length) throws SQLException {
- this.setStream(x, length);
- }
-
- public void setUnicodeStream(InputStream x, int length) throws SQLException {
- this.setStream(x, length);
- }
-
- public void setBinaryStream(InputStream x, int length) throws SQLException {
- this.setStream(x, length);
- }
- }
-